#region License Revision: 0 Last Revised: 6/18/2008 11:00 AM
/******************************************************************************
Copyright (c) Microsoft Corporation.  All rights reserved.


This file is licensed under the Microsoft Public License (Ms-PL). A copy of the Ms-PL should accompany this file. 
If it does not, you can obtain a copy from: 

http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
******************************************************************************/
#endregion // License
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace VIEWS
{
    /// <summary>
    /// Converts managed enums to and from script string values.
    /// </summary>
    static internal class ScriptEnumConverter
    {
        #region VEAltitudeMode
        /// <summary>
        /// Converts a <see cref="VEAltitudeMode"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEAltitudeMode value)
        {
            switch (value)
            {
                case VEAltitudeMode.Absolute:
                    return "Datum";
                case VEAltitudeMode.RelativeToGround:
                    return "Ground";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEAltitudeMode"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEAltitudeMode ToAltitudeMode(string value)
        {
            if (value == "Datum")
            {
                return VEAltitudeMode.Absolute;
            }
            else if (value == "Ground")
            {
                return VEAltitudeMode.RelativeToGround;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion // VEAltitudeMode

        #region VEClusteringType
        /// <summary>
        /// Converts a <see cref="VEClusteringType"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEClusteringType value)
        {
            switch (value)
            {
                case VEClusteringType.Grid:
                    return "Grid";
                case VEClusteringType.None:
                    return "None";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEClusteringType"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEClusteringType ToClusteringType(string value)
        {
            if (value == "Grid")
            {
                return VEClusteringType.Grid;
            }
            if (value == "None")
            {
                return VEClusteringType.None;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEClusteringType

        #region VEFindType
        /// <summary>
        /// Converts a <see cref="VEFindType"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEFindType value)
        {
            switch (value)
            {
                case VEFindType.Businesses:
                    return "YellowPageSearch";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEFindType"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEFindType ToFindType(string value)
        {
            if (value == "YellowPageSearch")
            {
                return VEFindType.Businesses;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEFindType

        #region VEMiniMapSize
        /// <summary>
        /// Converts a <see cref="VEMiniMapSize"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEMiniMapSize value)
        {
            switch (value)
            {
                case VEMiniMapSize.Large:
                    return "large";
                case VEMiniMapSize.Small:
                    return "small";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEMiniMapSize"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEMiniMapSize ToMiniMapSize(string value)
        {
            if (value == "large")
            {
                return VEMiniMapSize.Large;
            }
            if (value == "small")
            {
                return VEMiniMapSize.Small;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEMiniMapSize

        #region VEModelFormat
        /// <summary>
        /// Converts a <see cref="VEModelFormat"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEModelFormat value)
        {
            switch (value)
            {
                case VEModelFormat.OBJ:
                    return "OBJ";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEModelFormat"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEModelFormat ToModelFormat(string value)
        {
            if (value == "OBJ")
            {
                return VEModelFormat.OBJ;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEModelFormat

        #region VEModelScaleUnit
        /// <summary>
        /// Converts a <see cref="VEModelScaleUnit"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEModelScaleUnit value)
        {
            switch (value)
            {
                case VEModelScaleUnit.Centimeters:
                    return "Centimeters";
                case VEModelScaleUnit.Feet:
                    return "Feet";
                case VEModelScaleUnit.Inches:
                    return "Inches";
                case VEModelScaleUnit.Meters:
                    return "Meters";
                case VEModelScaleUnit.Millimeters:
                    return "Millimeters";
                case VEModelScaleUnit.Yards:
                    return "Yards";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEModelScaleUnit"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEModelScaleUnit ToModelScaleUnit(string value)
        {
            if (value == "Centimeters")
            {
                return VEModelScaleUnit.Centimeters;
            }
            if (value == "Feet")
            {
                return VEModelScaleUnit.Feet;
            }
            if (value == "Inches")
            {
                return VEModelScaleUnit.Inches;
            }
            if (value == "Meters")
            {
                return VEModelScaleUnit.Meters;
            }
            if (value == "Millimeters")
            {
                return VEModelScaleUnit.Millimeters;
            }
            if (value == "Yards")
            {
                return VEModelScaleUnit.Yards;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEModelScaleUnit

        #region VEModelStatusCode
        /// <summary>
        /// Converts a <see cref="VEModelStatusCode"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEModelStatusCode value)
        {
            switch (value)
            {
                case VEModelStatusCode.Failed:
                    return "Failed";
                case VEModelStatusCode.InvalidURL:
                    return "InvalidURL";
                case VEModelStatusCode.Success:
                    return "Success";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEModelStatusCode"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEModelStatusCode ToModelStatusCode(string value)
        {
            if (value == "Failed")
            {
                return VEModelStatusCode.Failed;
            }
            if (value == "InvalidURL")
            {
                return VEModelStatusCode.InvalidURL;
            }
            if (value == "Success")
            {
                return VEModelStatusCode.Success;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEModelStatusCode

        #region VEOrientation
        /// <summary>
        /// Converts a <see cref="VEOrientation"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEOrientation value)
        {
            switch (value)
            {
                case VEOrientation.East:
                    return "East";
                case VEOrientation.North:
                    return "North";
                case VEOrientation.South:
                    return "South";
                case VEOrientation.West:
                    return "West";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEOrientation"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEOrientation ToOrientation(string value)
        {
            if (value == "East")
            {
                return VEOrientation.East;
            }
            if (value == "North")
            {
                return VEOrientation.North;
            }
            if (value == "South")
            {
                return VEOrientation.South;
            }
            if (value == "West")
            {
                return VEOrientation.West;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEOrientation

        #region VERouteDistanceUnit
        /// <summary>
        /// Converts a <see cref="VERouteDistanceUnit"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VERouteDistanceUnit value)
        {
            switch (value)
            {
                case VERouteDistanceUnit.Kilometer:
                    return "Kilometer";
                case VERouteDistanceUnit.Mile:
                    return "Mile";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VERouteDistanceUnit"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VERouteDistanceUnit ToRouteDistanceUnit(string value)
        {
            if (value == "Kilometer")
            {
                return VERouteDistanceUnit.Kilometer;
            }
            if (value == "Mile")
            {
                return VERouteDistanceUnit.Mile;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VERouteDistanceUnit

        #region VERouteMode
        /// <summary>
        /// Converts a <see cref="VERouteMode"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VERouteMode value)
        {
            switch (value)
            {
                case VERouteMode.Driving:
                    return "Driving";
                case VERouteMode.Walking:
                    return "Walking";
                default:
                    throw new InvalidOperationException();
            }
        }
        /// <summary>
        /// Converts a string to a <see cref="VERouteMode"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VERouteMode ToRouteMode(string value)
        {
            if (value == "Driving")
            {
                return VERouteMode.Driving;
            }
            if (value == "Walking")
            {
                return VERouteMode.Walking;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VERouteMode

        #region VERouteOptimize
        /// <summary>
        /// Converts a <see cref="VERouteOptimize"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VERouteOptimize value)
        {
            switch (value)
            {
                case VERouteOptimize.Default:
                    return "Default";
                case VERouteOptimize.MinimizeDistance:
                    return "MinimizeDistance";
                case VERouteOptimize.MinimizeTime:
                    return "MinimizeTime";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VERouteOptimize"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VERouteOptimize ToRouteOptimize(string value)
        {
            if (value == "Default")
            {
                return VERouteOptimize.Default;
            }
            if (value == "MinimizeDistance")
            {
                return VERouteOptimize.MinimizeDistance;
            }
            if (value == "MinimizeTime")
            {
                return VERouteOptimize.MinimizeTime;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VERouteOptimize

        #region VEShapeType
        /// <summary>
        /// Converts a <see cref="VEShapeType"/> to it's script string value.
        /// </summary>
        /// <param name="value">
        /// The value to convert.
        /// </param>
        /// <returns>
        /// The converted value as a string.
        /// </returns>
        static public string ToString(VEShapeType value)
        {
            switch (value)
            {
                case VEShapeType.Polygon:
                    return "Polygon";
                case VEShapeType.Polyline:
                    return "Polyline";
                case VEShapeType.Pushpin:
                    return "Point";
                default:
                    throw new InvalidOperationException();
            }
        }

        /// <summary>
        /// Converts a string to a <see cref="VEShapeType"/> value.
        /// </summary>
        /// <param name="value">
        /// The string to convert.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public VEShapeType ToShapeType(string value)
        {
            if (value == "Polygon")
            {
                return VEShapeType.Polygon;
            }
            if (value == "Polyline")
            {
                return VEShapeType.Polyline;
            }
            if (value == "Point")
            {
                return VEShapeType.Pushpin;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        #endregion VEShapeType
    }
}
